﻿using fuzhu;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using XXX.Bo;
using XXX.Models.WDFT;
using XXX.Models;
using Yonyou.U8.BO;
using System;
using XXX.Common;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace XXX.api.Controllers
{
    /// <summary>
    /// 读取暂存库里内容
    /// </summary>
    [Route("api/wms/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class ST_Rdrecord_TmpController : ControllerBase
    {
        //private readonly IKuCunReqRepository _invRepository;
        private readonly ILogger<ST_Rdrecord_TmpController> _logger;
        private readonly ZDY_RDRECORDS_TMPVM _TMPVM;
        
        public ST_Rdrecord_TmpController(ILogger<ST_Rdrecord_TmpController> logger,ZDY_RDRECORDS_TMPVM TMPVM)
        {
            //_invRepository = xxxRepository;
            _logger = logger;
            _TMPVM = TMPVM;
        }
        [HttpGet]
        public Models.RetModel2 Get(string ccode, string ctype)
        {
          
            Models.RetModel2 ret = _TMPVM.ST_Rdrecord_Tmp_Get(ccode, ctype);

            return ret;
            //return ReturnStd.Success(jsonstr);
        }

        [HttpGet]
        public Models.RetModel2 Del(string ccode, string ctype)
        {
            
            Models.RetModel2 ret = _TMPVM.ST_Rdrecord_Tmp_Del(ccode, ctype);

            return ret;
            //return ReturnStd.Success(jsonstr);
        }

        [HttpGet]
        public Models.RetModel2 DelRow(string ccode, string ctype, string cBarcode)
        {
           
            Models.RetModel2 ret = _TMPVM.ST_Rdrecord_Tmp_DelRow(ccode, ctype, cBarcode);

            return ret;
            //return ReturnStd.Success(jsonstr);
        }

        [HttpPost]
        public Models.RetModel2 Save(JObject obj)
        {

          

                string requestBody = DbHelper.GetDbString(obj);
                if (requestBody == null)
                {
                    return DBService.ReErrObject("入参有误，没有数据");
                }

                try
                {
                    string cErr = "";
                    ScanBarcodeVM model = JsonConvert.DeserializeObject<ScanBarcodeVM>(requestBody);

                 
            Models.RetModel2 ret = _TMPVM.ST_Rdrecord_Tmp_Save(model);

            return ret;
            }
            catch (Exception ex)
            {
               
                return DBService.ReErrObject(ex.Message);
            }
            //return ReturnStd.Success(jsonstr);
        }
    } 
}
